using System;
using System.Collections;
using EPiServer.Common.Queries;

namespace EPiAbstractions.Common.Queries
{
    public class QueryHandlerFacade : IQueryHandlerFacade
    {
        private static QueryHandlerFacade _instance;

        public static QueryHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new QueryHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IQueryHandlerFacade Members

        public virtual TCollection GetQueryResult<TEntity, TCollection>(IQuery query) where TCollection : ICollection, IList, new()
        {
            return QueryHandler.GetQueryResult<TEntity, TCollection>(query);
        }

        public virtual TCollection GetQueryResult<TEntity, TCollection>(IQuery query, Int32 page, Int32 pageSize)
            where TCollection : ICollection, IList, new()
        {
            return QueryHandler.GetQueryResult<TEntity, TCollection>(query, page, pageSize);
        }

        public virtual TCollection GetQueryResult<TEntity, TCollection>(IQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
            where TCollection : ICollection, IList, new()
        {
            return QueryHandler.GetQueryResult<TEntity, TCollection>(query, page, pageSize, out totalItems);
        }

        public virtual TCollection GetQueryResult<TEntity, TCollection>(IQuery query, TimeSpan? explicitCacheTime, Int32 page,
                                                                        Int32 pageSize, out Int32 totalItems)
            where TCollection : ICollection, IList, new()
        {
            return QueryHandler.GetQueryResult<TEntity, TCollection>(query, explicitCacheTime, page, pageSize, out totalItems);
        }

        public virtual void RemoveQueryResultCache(IQuery query)
        {
            QueryHandler.RemoveQueryResultCache(query);
        }

        #endregion
    }
}